﻿using MasMembers.MainDataSetTableAdapters;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MasMembers
{
    public partial class ReportForm : Form
    {
        public ReportForm()
        {
            InitializeComponent();
        }

        //Define all crystal report staff here 
        private MainDataSet dataSet = new MainDataSet();

        //TableAdapter
        private MasMembers.MainDataSetTableAdapters.DataTable1TableAdapter basicInfoDataTable = new MasMembers.MainDataSetTableAdapters.DataTable1TableAdapter();



        private void cmboRprt_SelectedIndexChanged(object sender, EventArgs e)
        {
            hideAllPanels();
            if (cmboRprt.Text == "" || cmboRprt.Text == "" )
                pnlTxt.Visible = true;
            else if (cmboRprt.Text == "" || cmboRprt.Text == "" )
                pnlList.Visible = true;
            else if (cmboRprt.Text == "" || cmboRprt.Text == "" )
                pnlDate.Visible = true;
            else if (cmboRprt.Text == "فصيلة الدم")
            {
                pnlAddress.Visible = false;
                pnlMilitary_status.Visible = false;
                PnlBloodType.Visible = true;
                pnlDate.Visible = false;
                pnlQualificat.Visible = false;
            }
            else if (cmboRprt.Text == "المؤهلات")
            {
                pnlAddress.Visible = false;
                pnlMilitary_status.Visible = false;
                PnlBloodType.Visible = false;
                pnlDate.Visible = false;
                pnlQualificat.Visible = true;
            }
            else if (cmboRprt.Text == "الخدمة العسكريه")
            {
                pnlAddress.Visible = false;
                pnlMilitary_status.Visible = true;
                PnlBloodType.Visible = false;
                pnlDate.Visible = false;
                pnlQualificat.Visible = false;
            }
            else if (cmboRprt.Text == "العنوان")
            {
                pnlAddress.Visible = true;
                pnlMilitary_status.Visible = false;
                PnlBloodType.Visible = false;
                pnlDate.Visible = false;
                pnlQualificat.Visible = false;
            }
            
        }

        private void ReportForm_Load(object sender, EventArgs e)
        {
            hideAllPanels();
        }

        private void hideAllPanels() {
            pnlDate.Visible = false;
            pnlList.Visible = false;
            pnlTxt.Visible = false;
        }

        private bool isTextValidNumbers() {
            try
            {
                Int32.Parse(txtFrom.Text);
                Int32.Parse(txtTo.Text);
            }
            catch (Exception e)
            {
                MessageBox.Show("أدخل الأرقام بشكل صحيح");
                return false;
            }
        
            return true;
        }

        private void button1_Click(object sender, EventArgs e)
        {


            if(PnlBloodType.Visible==true)
            {
            if (cmboBloodType.Text == "الكل")
            {
                RprtBloodType rpt = new RprtBloodType();
                MainDataSet dataset = new MainDataSet();
                memIformTableAdapter adpter = new memIformTableAdapter();
                adpter.FillByAll(dataset.memIform);
                rpt.SetDataSource(dataset);
                rprtViewer.ReportSource = rpt;
            }
             else  
            {
                RprtBloodType rpt = new RprtBloodType();
                MainDataSet dataset = new MainDataSet();
                memIformTableAdapter adpter = new memIformTableAdapter();
                adpter.FillByBloodType(dataset.memIform, cmboBloodType.Text);
                rpt.SetDataSource(dataset);
                rprtViewer.ReportSource = rpt;

            }
        }
            else if (pnlQualificat.Visible == true)
            {
                if (cmbQualificat.Text == "الكل")
                {
                    RprtAccordingtoStudy rptStudy = new RprtAccordingtoStudy();
                    MainDataSet dataset2 = new MainDataSet();
                    memIformTableAdapter adp = new memIformTableAdapter();
                    adp.FillByAll(dataset2.memIform);
                    rptStudy.SetDataSource(dataset2);
                    rprtViewer.ReportSource = rptStudy;
                }
                else
                {
                    RprtAccordingtoStudy rptStudy = new RprtAccordingtoStudy();
                    MainDataSet dataset2 = new MainDataSet();
                    memIformTableAdapter adp = new memIformTableAdapter();
                    adp.FillByStudy(dataset2.memIform, cmbQualificat.Text);
                    rptStudy.SetDataSource(dataset2);
                    rprtViewer.ReportSource = rptStudy;
                }
            }
            else if (pnlMilitary_status.Visible==true)
            {
            if (cmbMilitary_status.Text == "الكل")
            {
                RprtAccordingtoMilitary_status rpt = new RprtAccordingtoMilitary_status();
                MainDataSet dataSet3 = new MainDataSet();
                memIformTableAdapter adpMilitary = new memIformTableAdapter();
                adpMilitary.FillByAll(dataSet3.memIform);
                rpt.SetDataSource(dataSet3);
                rprtViewer.ReportSource = rpt;

            }
            else
            {
                RprtAccordingtoMilitary_status rptMilitary = new RprtAccordingtoMilitary_status();
                MainDataSet dataset4 = new MainDataSet();
                memIformTableAdapter adpMilitary = new memIformTableAdapter();
                adpMilitary.FillByMilitary_status(dataset4.memIform, cmbMilitary_status.Text);
                rptMilitary.SetDataSource(dataset4);
                rprtViewer.ReportSource = rptMilitary;


            }
        }
            else if (pnlAddress.Visible == true)
            {
                RprtAccordingtoAddress rptaddress = new RprtAccordingtoAddress();
                MainDataSet datasetAddess = new MainDataSet();
                memIformTableAdapter adpAddess = new memIformTableAdapter();
                if (cmbAddress.Text == "الكل")
                {
                    adpAddess.FillByAll(datasetAddess.memIform);
                    rptaddress.SetDataSource(datasetAddess);
                    rprtViewer.ReportSource = rptaddress;

                }
                else
                {
                    adpAddess.FillByAdressCity(datasetAddess.memIform, cmbAddress.Text);
                    rptaddress.SetDataSource(datasetAddess);
                    rprtViewer.ReportSource = rptaddress;
                }
            }

        }

        private void label9_Click(object sender, EventArgs e)
        {

        }

        private void label8_Click(object sender, EventArgs e)
        {

        }


    }
}
